home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / coord2to3.pro < prev    next >
Text File  |  1997-07-08  |  2KB  |  80 lines

  1. ; $Id: coord2to3.pro,v 1.3 1997/01/15 03:11:50 ali Exp $
  2. ;
  3. ; Copyright (c) 1991-1997, Research Systems, Inc.  All rights reserved.
  4. ;    Unauthorized reproduction prohibited.
  5. ;
  6. FUNCTION COORD2TO3, MX, MY, DIM, D0, PTI
  7. ;+
  8. ; NAME:
  9. ;    COORD2TO3
  10. ;
  11. ; PURPOSE:
  12. ;    Return 3D data coordinates given the normalized X and Y screen
  13. ;    coordinates and one of the three data coordinates.
  14. ;
  15. ; CATEGORY:
  16. ;    Geometry / Graphics.
  17. ;
  18. ; CALLING SEQUENCE:
  19. ;    Result = COORD2TO3(Mx, My, Dim, D0 [, PTI])
  20. ;
  21. ; INPUTS:
  22. ;    Mx, My: The normalized X and Y screen coordinates.
  23. ;
  24. ;    Dim:      A parameter used to specify which data coordinate is fixed.
  25. ;        Use 0 for a fixed X data coordinate, 1 for a fixed Y data 
  26. ;        coordinate, or 2 for a fixed Z data coordinate.
  27. ;
  28. ;    D0:    The value of the fixed data coordinate.
  29. ;
  30. ; OPTIONAL INPUT PARAMETERS:
  31. ;    PTI:      The inverse of !P.T.  If this parameter is not supplied, 
  32. ;        or set to 0, COORD2TO3 computes the inverse.  If this routine
  33. ;        is to be used in a loop, the caller should supply PTI for
  34. ;        highest efficiency.
  35. ;
  36. ; KEYWORD PARAMETERS:
  37. ;    None.
  38. ;
  39. ; OUTPUTS:
  40. ;    Returns a 3-element vector containing the 3D data coordinates.
  41. ;
  42. ; COMMON BLOCKS:
  43. ;    None.
  44. ;
  45. ; SIDE EFFECTS:
  46. ;    None.
  47. ;
  48. ; RESTRICTIONS:
  49. ;    A valid 3D transform must exist in !P.T or PTI.
  50. ;    The axis scaling variables, !X.S, !Y.S and !Z.S must be valid.
  51. ;
  52. ; PROCEDURE:
  53. ;    The intersection of the plane determined by data coordinates
  54. ;    Dim and D0 and the screen coordinate line (Mx, My, 0),
  55. ;    (Mx, My, 1) is computed.
  56. ;
  57. ; EXAMPLE:
  58. ;    To return the data coordinates of the mouse, fixing the
  59. ;    data Z value at 10, enter the commands:
  60. ;        CURSOR, X, Y, /NORM    ;Get the normalized mouse coords.
  61. ;          P = COORD2TO3(X, Y, 2, 10.0)
  62. ;
  63. ; MODIFICATION HISTORY:
  64. ;    DMS, 9/91.
  65. ;-
  66.  
  67.  
  68. if n_elements(pti) le 0 then pti = invert(!p.t) $
  69.    else if total(pti) eq 0. then pti = invert(!p.t)
  70.  
  71. vs = [[!x.s], [!y.s], [!z.s]]
  72. a = d0 * vs[1,dim] + vs[0,dim]  ;To normalized data coords
  73.  
  74. ;    Solve for normalized screen Z
  75. az = (a - mx * pti[0,dim] - my * pti[1,dim] - pti[3,dim]) / pti[2,dim]
  76. p = [ mx, my, az, 1]        ;Normalized screen coords
  77. p = p # pti            ;to normalized 3d coords
  78. return, (p[0:2] - vs[0,*]) / vs[1,*] ;to 3d data coords.
  79. end
  80.